package org.ThreadDemo.collections;

import java.util.HashSet;
import java.util.List;
import java.util.Set;
import java.util.UUID;
import java.util.concurrent.CopyOnWriteArrayList;
import java.util.concurrent.CopyOnWriteArraySet;

public class ThreadDemoHashSet {

    /**
     *
     * List 线程不安全
     */
    public static void main(String[] args) {
       // List<String> list = new Vector<>();
        //List<String> list  = Collections.synchronizedList(new ArrayList<>());
        //List<String> list = new CopyOnWriteArrayList<>() ;

        //Set<String> set = new HashSet<>();

        Set<String> set = new CopyOnWriteArraySet<>();


        for(int i = 0;i<50 ;i++){
            new Thread(
                    ()->{
                        set.add(UUID.randomUUID().toString().substring(0,8));
                        System.out.println(set);
                    },String.valueOf(i)
            ).start();
        }
    }
}
